package com.flowable.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.common.util.Excel.ExcelUtil;
import com.core.flowable.domain.SysListener;
import com.flowable.Excel.SysListenerExcel;
import com.flowable.service.ISysListenerService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流程监听Controller
 *
 * @author Tony
 * @date 2022-12-25
 */
@RestController
@RequestMapping("/flowable/listener")
public class SysListenerExController {
    @Autowired
    private ISysListenerService sysListenerService;

    /**
     * 查询流程监听列表
     */

    @GetMapping("/list")
    @ApiOperation(value = " 查询流程监听列表接口")
    public ResponseEntity list(Page pageDto, SysListener sysListener) {
        return sysListenerService.selectSysListenerList(pageDto, sysListener);
    }


    /**
     * 获取流程监听详细信息
     */
    @GetMapping(value = "/{id}")
    @ApiOperation(value = " 获取流程监听详细信息")
    public ResponseEntity getInfo(@PathVariable("id") Long id) {
        return sysListenerService.selectSysListenerById(id);
    }

    /**
     * 新增流程监听
     */
    @PostMapping("/save")
    @ApiOperation(value = " 修改流程监听器接口")
    public ResponseEntity save(@RequestBody SysListener sysListener) {
        return sysListenerService.save(sysListener);
    }

    /**
     * 删除流程监听
     */

    @DeleteMapping("/del")
    @ApiOperation(value = " 删除流程监听器接口")
    public ResponseEntity remove(@RequestBody List<Long> ids) {
        return sysListenerService.deleteSysListenerByIds(ids.toArray(new Long[ids.size()]));
    }

    @ApiOperation("流程监听器导出")
    @PostMapping("/export")
    public void export(HttpServletResponse response) {
        ExcelUtil.export(response, "流程监听器数据", "流程监听器数据表", sysListenerService.ExportList(), SysListenerExcel.class);
    }

}
